Skip to content

Partial fix (#19589): retire closed Codex model-picker observations so a walled pane stops gating input - #19590

Closed
TheAbyss wants to merge 3 commits into
stablyai:mainfrom
TheAbyss:codex-modal-observation-partial
Closed

TheAbyss wants to merge 3 commits into
stablyai:mainfrom
TheAbyss:codex-modal-observation-partial

Conversation

@TheAbyss

@TheAbyss TheAbyss commented Sep 8, 2026 •

Copy link
Copy Markdown

Partial fix for #19589. Please treat this as evidence, not as a finished contribution.

What this does

Three commits on the runtime terminal/agent-prompt path, addressing the piece of #19589 where a Codex pane's model-picker / rate-limit modal is observed and retired:

commit change
50162543 retire closed Codex model picker permission observations
d9a5197e retain modal retirement across paste echoes and preserve working state
b872ca49 preserve synchronous terminal waiter admission across reloads

14 files, +492/−30, including two new test files (~309 lines): terminal-codex-modal-observation.test.ts and terminal-codex-modal-runtime.test.ts. The new module src/main/runtime/terminal-codex-modal-observation.ts (+82) is additive; the edits to existing runtime files are small.

The motivating symptom: a walled Codex pane renders a modal ("Approaching rate limits — switch to a cheaper model?") that is a reminder painted over a session that has already stopped. We measured selecting it on 13 walled panes with cursor position verified and keystrokes confirmed delivered — 0 of 13 cleared. Meanwhile the observation state kept the pane's input gated. These commits make the runtime distinguish a retired modal from a live one and stop that gating from outliving the modal.

What this does NOT do

Honesty about provenance, since it affects how much you should trust it

These commits were written by one of our automated agents. It correctly diagnosed the underlying defect and then went considerably further than we intended — it cloned this repository and started writing fixes across five branches, consuming a large amount of our Codex quota before we noticed and stopped it. That was our process failure, not a problem with Orca.

We are opening this PR so the diagnosis is not wasted. We are not planning to invest further in fixing this, and we are not offering to maintain the branch. If it is useful, take it, rewrite it, or cherry-pick the tests. If it is not, close it without hesitation — no follow-up needed from our side, and we will not be offended.

The issue (#19589) is the more valuable half: it documents the asymmetry that Codex needs a 25-file stale-account/restart apparatus while Claude needs none.


Update 2026-09-19 — second asymmetry, same root: per-account CODEX_HOME silently loses shared skills

While adding a skill for Codex we found that the per-account CODEX_HOME design in #19589 has a second cost beyond "panes cannot follow a switch": Orca-launched Codex seats do not see the user's skills, and nothing tells the user.

Intended behaviour (present on main today, src/main/codex/codex-home-paths.ts, last touched by 0b80a773a4 / #15287): CODEX_SYSTEM_RESOURCE_ENTRIES lists skills, hooks, plugins, plugin-state, profile-v2, themes, prompts, AGENTS.md, and syncSystemCodexResourcesIntoManagedHome() is meant to symlink each of them from ~/.codex into every managed home, so a per-account launch home "is complete without ever symlinking into or mutating the user's real ~/.codex".

Observed (Orca 1.4.205, Codex CLI 0.154.0, macOS, 6 Codex accounts):

entry shared runtime mirror per-account homes (6)
AGENTS.md — symlink → ~/.codex/AGENTS.md in 6/6
plugins — symlink in 5/6; real dir (cache/) in 1/6
skills symlink → ~/.codex/skills real directory in 6/6, containing only .system/ and cache/

So every account home had AGENTS.md and the global config.toml from ~/.codex, and none of the three skills installed in ~/.codex/skills. A skill added by the documented Codex route (~/.codex/skills/<name>/SKILL.md) is therefore invisible in every Orca-launched Codex pane, while the same user's Claude panes see all of ~/.claude/skills because Claude account switching persists only auth and never swaps CLAUDE_CONFIG_DIR (global-settings-types.ts:287 says exactly that).

Why the link is missing: Codex CLI materialises $CODEX_HOME/skills/.system/ (its bundled skills) and plugins/cache/ itself on first launch. If that happens before linkSystemCodexResource runs for the entry, or after the entry is removed, the target is now a real directory that Orca did not create. linkSystemCodexResource then takes the branch

if (targetObservation.kind === 'present' && !shouldRefreshFallbackCopy) {
  return
}

and returns without a log line (the only console.warns in that function are for a non-file AGENTS.md and for copy fallbacks). That branch is correct for user-created runtime resources, but a directory whose only contents are Codex's own .system/ is not user content, and the silence is what turned a race into six permanently divergent homes.

Suggested fix, in ascending ambition:

  1. Log at warn when a system resource is skipped because the target is a foreign real directory, naming the home and the entry. This alone would have surfaced the defect on day one.
  2. Treat a skills/ target that contains only Codex-owned entries (.system/, cache/) as replaceable: move it aside and install the link, or link the individual ~/.codex/skills/* children into it.
  3. Run the resource sync after the first Codex launch has settled as well as before, since Codex re-creates .system/ whenever it is absent.

Workaround we applied locally (per home): move the real skills/ aside and ln -s ~/.codex/skills "$HOME/skills"; all six homes now list the same four skills. A newly added account will hit the same race until the ordering or the skip branch changes.

Filed here rather than as a separate issue because it is the same root cause as #19589: binding identity into CODEX_HOME forces Orca to re-create the user's whole Codex environment per account, and every entry it re-creates is a place it can silently diverge. Happy to split it into its own issue if you prefer.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Sound partial fix — no correctness or security regression on the code's own merits — but it is not mergeable as-is (it conflicts with current main) and one durability gap undercuts the "across reloads" claim. Details below.

Reviewed changes

This run reviewed the three commits on the terminal/agent-prompt path that retire a dismissed Codex model-picker so its retained scrollback stops gating sendTerminalAgentPrompt.

  • New TerminalCodexModalObservation module — a WeakMap-backed retirement that slices a dismissed picker's prefix out of future wait text, fenced by pane generation, output sequence, and permission sequence.
  • Status/wait plumbing — refreshModal, isModalComposerReady, and getWaitText threaded through RuntimeTerminalAgentStatusQuery, the idle polls, and RuntimeTerminalWait, replacing direct buildTerminalWaitText calls.
  • Write-gate tightening — writeTerminalAgentPrompt now captures a pre-refresh baseline and compares permission sequence across the modal refresh (previously a self-comparison no-op).
  • Composer detection — projectTerminalVisibleLines surfaces whether the Codex composer placeholder is present, used to confirm the visible screen is a clean composer before retiring.
  • Two test files (~309 lines) covering fail-closed fencing, live-approval preservation, paste-echo retention, and permission cycles during the screen read.

⚠️ Conflicts with current main; not mergeable without a rebase

The branch is based on 28373fce and its merge-base with main (bba68b1) is 28373fce, so it sits behind a main that has moved well ahead. The author reports 9 conflict indicators and states they will not rebase or maintain the branch, so this cannot land as-is — the realistic paths are cherry-picking the observation module and tests, or closing. The rest of this review therefore evaluates the diff on its own merits rather than as a ready-to-merge change.

⚠️ Retirement is keyed by record identity, so it may not survive a renderer reload

TerminalCodexModalObservation.retired is a WeakMap keyed by the exact record object, and refreshModal / isModalComposerReady / getWaitText all select that object via getLivePty(handle)?.pty ?? getLiveLeaf(handle).leaf. A retirement recorded against the PTY record is invisible to a later read against the leaf record (and vice versa), and a graph reload that rebuilds the RuntimeLeafRecord / RuntimePtyWorktreeRecord objects drops the entry entirely. The pane then re-gates — safe (fail-closed), but it means the fix does not stick across the reload scenario that commit b872ca49 ("preserve synchronous terminal waiter admission across reloads") claims to address.

Technical details
# Reload durability of modal retirement

## Affected sites
- src/main/runtime/terminal-codex-modal-observation.ts:31 — `private readonly retired = new WeakMap<object, Retirement>()` (identity keyed)
- src/main/runtime/runtime-terminal-agent-status-query.ts:154 — `record` selected as `getLivePty(handle)?.pty ?? getLiveLeaf(handle).leaf`
- src/main/runtime/runtime-terminal-agent-status-query.ts:165 — `getWaitText(record, ptyId)` reads retirement against whichever record the caller passes

## Required outcome
- Retirement must survive the identity changes that occur across a renderer reload / graph re-sync, or be explicitly scoped as best-effort within a single projection.

## Open questions for the human
- Are leaf/pty records mutated in place or rebuilt on graph reload? If rebuilt, the `WeakMap` entry is lost and the "across reloads" claim does not hold.

ℹ️ Nitpicks

  • getWaitText computes getModalFence(ptyId) — which lazily allocates a lifecycle generation via getPtyLifecycleGeneration — on every read, even for non-Codex or non-retired panes. It could be gated on isCodex / presence of a retirement.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

type Retirement = TerminalModalFence & { prefix: string }

// Only the model/effort picker can be retired without an agent lifecycle event.
export function hasCodexModelPickerTail(text: string): boolean {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The picker fingerprint here is pinned to exact Codex UI strings (Select model, reasoning effort, Press enter to confirm or esc to go back). A future Codex wording change silently disables retirement — safe, since it fails closed, but the fix stops firing with no signal. A log or metric when press enter to confirm is present but the model/effort context isn't would make that degradation visible.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The runtime now detects Codex composer state and observes model-picker modal output. Modal text is reconciled with lifecycle, output, and permission fences before it affects terminal status. Terminal waits and idle polls use modal-aware wait text. Prompt submission refreshes modal state before permission validation. New tests cover modal fencing, picker retirement, idle behavior, blocked screens, permission changes, and prompt submission.

Priority: ⬇️ Low — Defer this runtime change because it addresses stale Codex modal observations gating terminal input within the terminal agent path.

Merge Risk: 🟡 Moderate · up to b872c

Prompts can be admitted while an active model picker owns the terminal, and cancelled or short waits may remain blocked during modal refresh. These runtime behaviors should be corrected before merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 14 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the problem, scope, implementation, limitations, testing scope, and linked issue. However, it omits most required template sections, including Visual Proof, Testing checklist,… Complete the repository template. Add the required sections and checklist items, provide before-and-after visual proof for the behavior change or write N/A with a reason, document manual and automated testing with platforms, complete the …
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: retiring closed Codex model-picker observations so stale modal state no longer gates input.
Full details: Description check

Explanation

The description explains the problem, scope, implementation, limitations, testing scope, and linked issue. However, it omits most required template sections, including Visual Proof, Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. It also does not provide the required visual proof or explicitly state N/A.

Resolution

Complete the repository template. Add the required sections and checklist items, provide before-and-after visual proof for the behavior change or write N/A with a reason, document manual and automated testing with platforms, complete the AI Disclosure and Agent skill upstream boundary sections, and summarize security, cross-platform, SSH, mobile, compatibility, and performance considerations.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch codex-modal-observation-partial

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: f2228e32-a888-413e-842d-7538d1cc998e

📥 Commits

Reviewing files that changed from the base of the PR and between bba68b1 and b872ca4.

📒 Files selected for processing (14)
  • src/main/runtime/orca-runtime-core.ts
  • src/main/runtime/orca-runtime-create-agent-prompt-render-gate.ts
  • src/main/runtime/orca-runtime-get-terminal-interactive-wait.ts
  • src/main/runtime/orca-runtime-runtime-id.ts
  • src/main/runtime/orca-runtime-stop-requested-pty-ids.ts
  • src/main/runtime/orca-runtime-terminal-projection.ts
  • src/main/runtime/orca-runtime-write-terminal-agent-prompt.ts
  • src/main/runtime/runtime-terminal-agent-status-query.ts
  • src/main/runtime/runtime-terminal-idle-polls.ts
  • src/main/runtime/runtime-terminal-state-records.ts
  • src/main/runtime/runtime-terminal-wait.ts
  • src/main/runtime/terminal-codex-modal-observation.test.ts
  • src/main/runtime/terminal-codex-modal-observation.ts
  • src/main/runtime/terminal-codex-modal-runtime.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

try {
const ptyId = this.getTerminalAgentStatusPtyId(handle)
if (this.terminalAgentStatus.hasModalToRefresh(handle, ptyId)) {
await this.terminalAgentStatus.refreshModal(handle, ptyId)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -e
rg -n -C 12 'refreshModal|readVisibleTerminalState|terminalWait\.wait|waitForTerminal|renderer.*reload|reload.*renderer' src/main

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- target file ---'
sed -n '1,190p' src/main/runtime/orca-runtime-create-agent-prompt-render-gate.ts
printf '%s\n' '--- definition files ---'
rg -l 'readVisibleTerminalState|refreshModal' src/main --glob '*.ts' --glob '*.tsx' | sort
printf '%s\n' '--- waiter definitions ---'
rg -l 'class .*Terminal.*Wait|terminalWait|waitForTerminal' src/main --glob '*.ts' --glob '*.tsx' | sort | head -80

Repository: stablyai/orca

Length of output: 10423


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- status implementation locations ---'
rg -n -C 10 'refreshModal|readVisibleTerminalState|hasModalToRefresh|isModalComposerReady' \
  src/main/runtime/runtime-terminal-agent-status-query.ts \
  src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts \
  src/main/runtime/orca-runtime-get-terminal-interactive-wait.ts \
  src/main/runtime/orca-runtime-visible-snapshot-preview.ts
printf '%s\n' '--- waiter implementation ---'
sed -n '1,280p' src/main/runtime/runtime-terminal-wait.ts
printf '%s\n' '--- reload/read bindings ---'
rg -n -C 8 'readVisibleTerminalState|markRendererReloading|rendererGraph|reloading|webContents|executeJavaScript|invoke' \
  src/main/runtime/runtime-terminal-agent-status-query.ts \
  src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts \
  src/main/runtime --glob '*.ts' | head -500

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- visible-state read implementation ---'
sed -n '30,145p' src/main/runtime/orca-runtime-visible-snapshot-preview.ts
printf '%s\n' '--- visible-state helpers and lifecycle invalidation ---'
rg -n -C 10 'loadVisibleTerminalState|providerVisibleStateReadsByPtyId|readRendererVisibleSnapshotLines|readVisibleState|clear.*Visible|delete\(ptyId\)|getPtyLifecycleGeneration' \
  src/main/runtime/orca-runtime-visible-snapshot-preview.ts \
  src/main/runtime/orca-runtime-capture-provider-terminal-buffer.ts \
  src/main/runtime --glob '*.ts' | head -400

Repository: stablyai/orca

Length of output: 42651


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- provider snapshot acquisition ---'
rg -n -C 18 'serializeProviderTerminalBuffer|VISIBLE_TERMINAL_SNAPSHOT_TIMEOUT_MS|withTimeout|providerSnapshotPreferredPtys' \
  src/main/runtime/orca-runtime-capture-provider-terminal-buffer.ts \
  src/main/runtime/orca-runtime-visible-snapshot-preview.ts \
  src/main/runtime/runtime-async-boundaries.ts \
  src/main/runtime --glob '*.ts' | head -500
printf '%s\n' '--- provider controller contract ---'
rg -n -C 12 'serializeProviderBuffer|serializeBuffer' src/main/runtime src/main/pty src/main --glob '*.ts' | head -350

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- provider buffer method ---'
sed -n '1,90p' src/main/runtime/orca-runtime-capture-provider-terminal-buffer.ts
printf '%s\n' '--- timeout contract ---'
rg -n -C 12 'export.*withTimeout|function withTimeout|promise-timeout-fallback|VISIBLE_TERMINAL_SNAPSHOT_TIMEOUT_MS' \
  src/shared src/main/runtime --glob '*.ts' | head -220
printf '%s\n' '--- preferred-set transitions ---'
rg -n -C 8 'providerSnapshotPreferredPtys\.(add|delete)|providerSnapshotPreferredPtys\s*=' \
  src/main/runtime --glob '*.ts' | head -260

Repository: stablyai/orca

Length of output: 46085


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- bounded provider acquisition ---'
rg -n -C 18 'serializeProviderTerminalBuffer|class OrcaRuntimeWithSerializeTerminalBufferFromAvailableState' \
  src/main/runtime/orca-runtime-serialize-terminal-buffer-from-available-state.ts
printf '%s\n' '--- headless write-chain construction ---'
rg -n -C 12 'writeChain\s*=|writeChain:|createPtyHeadlessTerminalState|acceptPtyData' \
  src/main/runtime/orca-runtime-create-pty-headless-terminal-state.ts \
  src/main/runtime/orca-runtime-serialize-main-terminal-buffer.ts \
  src/main/runtime/orca-runtime-accept-pty-data.ts \
  src/main/runtime --glob '*.ts' | head -450
printf '%s\n' '--- modal/reload tests ---'
rg -n -C 14 'refreshModal|readVisibleTerminalState|renderer reload|markRendererReloading|request_aborted|timeout' \
  src/main/runtime/terminal-codex-modal-runtime.test.ts \
  src/main/runtime/terminal-interactive-wait-visibility.test.ts \
  src/main/runtime/orca-runtime-tests --glob '*.spec.ts' | head -500

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -e
sed -n '108,165p' src/main/runtime/orca-runtime-serialize-terminal-buffer-from-available-state.ts
printf '%s\n' '--- renderer reload lifecycle entry points ---'
rg -n -C 12 'markRendererReloading|markRendererGraph|renderer.*reloading|reloading.*renderer|disposeHeadlessTerminal|replaceHeadlessTerminalAfterExecutionContextChange' \
  src/main/runtime/orca-runtime-*.ts | head -450

Repository: stablyai/orca

Length of output: 45808


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- headless data chain ---'
sed -n '145,185p' src/main/runtime/orca-runtime-maybe-hydrate-headless-from-renderer.ts
printf '%s\n' '--- emulator write contract ---'
rg -n -C 15 'async write|write\(' src/main/daemon/headless-emulator.ts src/main/daemon --glob '*.ts' | head -260
printf '%s\n' '--- renderer reload implementation ---'
sed -n '20,115p' src/main/runtime/orca-runtime-has-terminals-for-worktree.ts

Repository: stablyai/orca

Length of output: 27401


Preserve timeout and abort during modal refresh.

refreshModal does not use the caller's signal or deadline. Its provider path has a separate 750 ms timeout, while its headless path awaits writeChain without that deadline. Because this runs before terminalWait.wait binds the options, a short timeout or abort cannot take effect until the refresh returns. Register the waiter first, or apply the same signal and remaining timeout to the refresh.


getWaitText(record: RuntimePtyWorktreeRecord | RuntimeLeafRecord, ptyId: string | null): string {
const text = buildTerminalWaitText(record.tailBuffer, record.tailPartialLine, record.preview)
return ptyId ? this.modal.read(record, text, this.deps.getModalFence(ptyId)) : text

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reconcile a reopened picker before applying retirement.

TerminalCodexModalObservation.read ignores newer outputSequence values. A later identical picker in the same generation and permission sequence can therefore be stripped again. hasModalToRefresh then sees filtered text, skips refreshModal, and does not inspect the visible state. The wait path can admit tui-idle, allowing prompt submission while the picker is active. Detect the picker from raw wait text, clear retirement when newer visible state shows the active picker, and retain retirement only for confirmed composer echoes. Add a regression test for reopening the identical picker in one PTY generation.

@TheAbyss

Copy link
Copy Markdown
Author

@brennanb2025 @nwparker — pointer only, no action requested here.

I've asked for a disposition on the underlying issue (#19589), since an independent reproduction has since landed in #20142 (Windows, 1.4.200) and nothing in v1.4.199–v1.4.204 touches the running-pane account switch.

This PR itself stands as described in the original post: partial, unrebased (conflicts with current main), not CI-verified, and not maintained by us. Closing it costs us nothing — the diagnosis in #19589 and the two test files here are the only parts worth salvaging. Please don't let it sit open on our account.

@TheAbyss

Copy link
Copy Markdown
Author

Added a dated section to the description: a second consequence of per-account CODEX_HOME — Orca's syncSystemCodexResourcesIntoManagedHome intends to link ~/.codex/skills into every account home, but Codex writes skills/.system/ first and the linker's present-target branch returns silently, so on our machine 6/6 account homes had no user skills while AGENTS.md and config.toml were mirrored fine. Details, table and a three-step fix suggestion are in the description; happy to split into its own issue.

@nwparker

Copy link
Copy Markdown
Contributor

Closing this abandoned partial PR as requested by its author. The PR states that it is unrebased, conflicts with current main, has not been CI-verified, and will not be maintained. The diagnosis and test ideas remain in this PR for reference; #19589 stays open for the underlying Codex account-switch issue.

@nwparker nwparker closed this Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants